<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="created" content="2018-10-23T06:18:10.521000000">
    <meta name="changed" content="2018-10-23T06:18:42.262000000">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="de">
    <title>
      Using subcircuits
    </title>
    <link rel="stylesheet" type="text/css" href="../../style.css">
  </head>
  <body>
    <div class="maindiv">
      <h1>
        Using subcircuits
      </h1>
      <p>
        Now suppose we want to build a 4-to-1 multiplexer using instances of our 2-to-1 multiplexer. Of course, we would first create a new circuit, which we'll call <b class=reffig>Mux_4to1</b> To add 2-to-1 multiplexers into our circuit, we click the <b class=reffig>Mux_2to1</b> circuit <b>once</b> in the explorer pane to select it as a tool, and then we can add copies of it, represented as boxes, by clicking within the canvas.
      </p>
      <p align="center">
        <img src="../../../img-guide/subcirc-3-add.png" alt="#########">
      </p>
      <p>
        If you were to double-click the <b class=reffig>Mux_2to1</b> circuit in the explorer pane, then the window would switch to editing the <b class=reffig>Mux_2to1</b> circuit instead.
      </p>
      <p>
        After building up the circuit, we end up with the following.
      </p>
      <p align="center">
        <img src="../../../img-guide/subcirc-4-done.png" alt="#########">
      </p>
      <p>
        Our circuit for a 4-to-1 multiplexer uses three copies of the 2-to-1 multiplexer,each is drawn in a box with pins on the left and right sides. The pins on this box correspond to the input and output pins in the <b class=reffig>Mux_2to1</b> circuit. The two pins on the east face of the box correspond to the inputs of the circuit and on the west face they correspond to the output. They are read from the diagram of the sub-circuit from right to left and from top to bottom and they will be placed on the sub-circuit symbol from top to bottom.
      </p>
      <p>
        If labels have been associated with these pins in the diagram they will be included in the symbol. In addition, they are also displayed as a <b>tooltip</b> when you fly over the pin with the mouse. You can disable this feature through the <a href="../prefs/pref-layout.html">preferences panel</a> .)
      </p>
      <p align="center">
        <img class="notscal" src="../../../img-guide/subcirc-4-tip.png" alt="#########">
      </p>
      <p>
        Several other components will display these tips, too: For some of the pins of a built-in <a href="../../libs/mem/flipflops.html">flip-flop</a>, for example, hovering over it explains what that pin does.
      </p>
      <p>
        Incidentally, every pin to a circuit must be either an input or an output. Many manufactured chips have pins that behave as an input in some situations and as an output in others; you cannot construct such chips within Logisim (at least, in the current version).
      </p>
      <p>
        Logisim will maintain different state information for all subcircuits appearing in a circuit. For example, if a circuit contains a flip-flop, and that circuit is used as a subcircuit several times, then each subcircuit's flip-flop will have its own value when simulating the larger circuit.
      </p>
      <p>
        Now that we have the 4-to-1 multiplexer defined, we can now use it in other circuits. Logisim has no limits on how deeply circuits can be nested - though it will object to nesting circuits within themselves!
      </p>
      <p>
        <b class=note>Note:</b> There's nothing wrong with editing a circuit that is being used as a subcircuit; in fact, this is quite common. Be aware, though, that any changes to a circuit's pins (adding, deleting, or moving them) will rearrange them also in the containing circuit. Thus, if you change any pins in a circuit, you will also need to edit any circuits using it as a subcircuit.
      </p>
      <p>
        <b>Next:</b> <a href="sub-appear.html">Editing subcircuit appearance</a>.
      </p>
    </div>
  </body>
</html>
